home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / demobook / busycursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  7.0 KB  |  240 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /******************************************************************************
  18. **  
  19. **  NAME
  20. **    busycursor.c - functions for turning on and off demobook busy cursor
  21. **
  22. **  DESCRIPTION
  23. **    Lots of code ripped off from the ViewKit VkSimpleWindow, VkApp, and
  24. **    VkGetResources to turn on and off a busy cursor when demobook does
  25. **    large file reads.  Basically, this code creates and maps a window
  26. **    over the demobook application when the a busy cursor is desired.
  27. **    When the cursor is no longer is desired, the window is unmapped.
  28. **    The window has the busy cursor attached to it.
  29. **
  30. **  EXTERNAL FUNCTIONS
  31. **    void    setbusycursor()
  32. **    void    clearbusycursor()
  33. **
  34. **  AUTHOR
  35. **    Dave Ciemiewicz (ciemo)
  36. **  
  37. ******************************************************************************/
  38.  
  39. #include <X11/Intrinsic.h>
  40. #include <Xm/Xm.h>
  41. #include "exinterfmotif.h"
  42. #include <stdio.h>
  43. #include <assert.h>
  44.  
  45.  
  46. Window busywindow = NULL;
  47. Cursor busycursor = NULL;
  48.  
  49.  
  50. static XtPointer getresource(Widget w,
  51.                         const char * name,
  52.                         const char * className,
  53.                         const char * desiredType,
  54.                         int size,
  55.                         const char * defaultValue);
  56.  
  57. static void initbusywindow();
  58.  
  59.  
  60. void
  61. setbusycursor()
  62. {
  63.     if (!busywindow)
  64.     {
  65.     initbusywindow();
  66.     }
  67.  
  68.     if (busywindow) {
  69.     XMapWindow(XtDisplay(DBtoplevel), busywindow);
  70.     }
  71.  
  72.     XmUpdateDisplay(DBtoplevel);
  73. }
  74.  
  75.  
  76. void
  77. clearbusycursor()
  78. {
  79.     if (busywindow) {
  80.     XUnmapWindow(XtDisplay(DBtoplevel), busywindow);
  81.     }
  82. }
  83.  
  84.  
  85.  
  86. #define time32_width 32
  87. #define time32_height 32
  88. #define time32_x_hot 15
  89. #define time32_y_hot 15
  90. static unsigned char time32_bits[] = {
  91.    0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
  92.    0x8c, 0x00, 0x00, 0x31, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
  93.    0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
  94.    0x8c, 0x00, 0x00, 0x31, 0x0c, 0x7f, 0xfe, 0x30, 0x0c, 0xfe, 0x7f, 0x30,
  95.    0x0c, 0xfc, 0x3f, 0x30, 0x0c, 0xf8, 0x1f, 0x30, 0x0c, 0xe0, 0x07, 0x30,
  96.    0x0c, 0x80, 0x01, 0x30, 0x0c, 0x80, 0x01, 0x30, 0x0c, 0x60, 0x06, 0x30,
  97.    0x0c, 0x18, 0x18, 0x30, 0x0c, 0x04, 0x20, 0x30, 0x0c, 0x02, 0x40, 0x30,
  98.    0x0c, 0x01, 0x80, 0x30, 0x8c, 0x00, 0x00, 0x31, 0x4c, 0x80, 0x01, 0x32,
  99.    0x4c, 0xc0, 0x03, 0x32, 0x4c, 0xf0, 0x1f, 0x32, 0x4c, 0xff, 0xff, 0x32,
  100.    0xcc, 0xff, 0xff, 0x33, 0x8c, 0xff, 0xff, 0x31, 0xfe, 0xff, 0xff, 0x7f,
  101.    0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00};
  102.  
  103. #define time32m_width 32
  104. #define time32m_height 32
  105. static unsigned char time32m_bits[] = {
  106.    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  107.    0xcf, 0x00, 0x00, 0xf3, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
  108.    0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
  109.    0xce, 0x00, 0x00, 0x73, 0x8e, 0x7f, 0xfe, 0x71, 0x0e, 0xff, 0xff, 0x70,
  110.    0x0e, 0xfe, 0x7f, 0x70, 0x0e, 0xfc, 0x3f, 0x70, 0x0e, 0xf8, 0x1f, 0x70,
  111.    0x0e, 0xe0, 0x07, 0x70, 0x0e, 0xe0, 0x07, 0x70, 0x0e, 0x78, 0x1e, 0x70,
  112.    0x0e, 0x1c, 0x38, 0x70, 0x0e, 0x06, 0x60, 0x70, 0x0e, 0x03, 0xc0, 0x70,
  113.    0x8e, 0x01, 0x80, 0x71, 0xce, 0x00, 0x00, 0x73, 0x6e, 0x80, 0x01, 0x76,
  114.    0x6e, 0xc0, 0x03, 0x76, 0x6e, 0xf0, 0x1f, 0x76, 0x6e, 0xff, 0xff, 0x76,
  115.    0xee, 0xff, 0xff, 0x77, 0xcf, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff,
  116.    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  117.  
  118.  
  119. static void
  120. initbusywindow()
  121. {
  122.     Display*    dpy;
  123.     Pixmap    pixmap;
  124.     Pixmap    maskpixmap;
  125.     XColor    xcolors[2];
  126.     
  127.     dpy = XtDisplay(DBtoplevel);
  128.  
  129.     busywindow = XCreateWindow(dpy, XtWindow(DBtoplevel), 0, 0,
  130.                 DisplayWidth(dpy,DefaultScreen(dpy)),
  131.                 DisplayHeight(dpy,DefaultScreen(dpy)),
  132.                 0, 0, InputOnly,
  133.                 DefaultVisualOfScreen(XtScreen(DBtoplevel)),
  134.                 NULL, 0);
  135.  
  136.  
  137.     pixmap = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy),
  138.                     (char*)time32_bits,
  139.                     time32_width, time32_height);
  140.  
  141.     maskpixmap = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy),
  142.                     (char*)time32m_bits,
  143.                     time32m_width, time32m_height);
  144.  
  145.  
  146.     xcolors[0].pixel= (Pixel) getresource(DBtoplevel,
  147.                     "busyCursorForeground",
  148.                     XmCForeground,
  149.                     XmRPixel,
  150.                     sizeof(Pixel),
  151.                     (char *) "Red");
  152.  
  153.     xcolors[1].pixel= (Pixel) getresource(DBtoplevel,
  154.                     "busyCursorBackground",
  155.                     XmCBackground,
  156.                     XmRPixel,
  157.                     sizeof(Pixel),
  158.                     (char *) "White");
  159.  
  160.     XQueryColors (dpy, DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)),
  161.                       xcolors, 2);
  162.  
  163.  
  164.     busycursor = XCreatePixmapCursor (dpy, pixmap, maskpixmap,
  165.                                         &(xcolors[0]), &(xcolors[1]),
  166.                     time32_x_hot, time32_y_hot);
  167.  
  168.  
  169.     XDefineCursor(dpy,busywindow,busycursor);
  170.  
  171.     XFreePixmap (dpy, pixmap);
  172.     XFreePixmap (dpy, maskpixmap);
  173. }
  174.  
  175.  
  176. #include <X11/IntrinsicP.h>
  177.  
  178. static char*
  179. XtClassName(Widget w)
  180. {
  181.     return XtClass(w)->core_class.class_name;
  182. }
  183.  
  184.  
  185. static XtPointer
  186. getresource(Widget w,
  187.         const char * name,
  188.         const char * className,
  189.         const char * desiredType,
  190.         int size,
  191.         const char * defaultValue)
  192. {
  193.     static XtPointer  return_value = NULL;
  194.     XtResource request_resources;
  195.  
  196.     assert(size <= sizeof(XtPointer));
  197.  
  198.     request_resources.resource_name   = (char *) name;
  199.     request_resources.resource_class  = (char *) className;
  200.     request_resources.resource_type   = (char *) desiredType;
  201.     request_resources.resource_size   = size;
  202.     request_resources.default_type    = XmRString;
  203.     request_resources.resource_offset = 0;
  204.     request_resources.default_addr    = (XtPointer) defaultValue;
  205.  
  206.  
  207.  
  208.     XtGetSubresources(w,
  209.                       (XtPointer) &return_value,
  210.                       XtName(w),
  211.                       XtClassName(w),
  212.                       &request_resources,
  213.                       1,
  214.                       NULL,
  215.                       0);
  216.  
  217.     if (!strcmp(desiredType, XmRString))
  218.     {
  219.         return return_value;
  220.     }
  221.     else
  222.     {
  223.         if (size == sizeof(long))
  224.             return (XtPointer) *(long *) &return_value;
  225.         else if (size == sizeof(short))
  226.             return (XtPointer) *(short *)&return_value;
  227.         else if (size == sizeof(char))
  228.         {
  229.             char value = *(char *)&return_value;
  230.             return (XtPointer) value;
  231.         }
  232.         else if (size == sizeof(XtArgVal))
  233.             return *(XtPointer *)&return_value;
  234.     }
  235.  
  236.     return return_value;
  237. }
  238.  
  239.  
  240.